import { onMounted } from 'vue'

type Option={
    el:string
}

export default function ( options:Option):Promise<{base64Url:string}> {
    return new Promise((resolve)=>{
        onMounted(()=>{
            let img:HTMLImageElement = document.querySelector(options.el) as HTMLImageElement
           console.log('img',img)
           img.onload=()=>{
              
               // 图片加载完成
               resolve({
                base64Url: base64(img)
               })
           }
          
       })
       const base64=(el:HTMLImageElement)=>{
           const canvas = document.createElement('canvas')
           const ctx = canvas.getContext('2d')
           canvas.width = el.width
           canvas.height = el.height
           console.log('el',el)
           ctx?.drawImage(el, 0, 0, el.width, el.height)
           return canvas.toDataURL('image/png')
       }

    })
 
}